﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;

namespace WXYW
{
    public partial class ManageProductClass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindProductClassGridView();
            }
        }

        private void BindProductClassGridView()
        {
            ProductClassService service = new ProductClassService();
            ProductClassGridView.DataSource = service.GetAllClass();
            ProductClassGridView.DataBind();
        }

        protected void ProductClassGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                ((Label)e.Row.FindControl("IDLbl")).Text = (e.Row.RowIndex + 1).ToString();
            }
        }

        protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string classID = e.CommandArgument.ToString();
            switch (e.CommandName)
            {
                case "EditType":
                    Response.Redirect(string.Format("EditProductClass.aspx?{0}={1}", Constants.QUERYSTR_PRODUCT_CLASS_ID, classID));
                    break;
                case "DeleteType":
                    try
                    {
                        ProductClassService service = new ProductClassService();
                        service.DeleteProductClassByID(Convert.ToInt32(classID));
                        BindProductClassGridView();
                    }
                    catch (Exception ex)
                    {
                        string alertStr = "alert('删除失败，" + ex.Message + "');";
                        ClientScript.RegisterStartupScript(this.GetType(), "tip", alertStr, true);
                    }
                    break;
            }
        }
    }
}
